package com.printable;

import java.awt.FontMetrics;
import java.awt.Graphics2D;

public class PrinterHelper {
	private int height;
	private int width;
	
	private int xStart;
	private int yStart;
	private int yCount;
	
	private int yTextInc;
	private int yTitleTextInc;
	
	/**
	 * public 方法区
	 */
	public String splitStringByWidth(Graphics2D g2d, String str , int width) {
		String subString = str;
		FontMetrics fm = g2d.getFontMetrics(); 
		int stringWidth = fm.stringWidth(subString);
		while (stringWidth > width) {
			subString = subString.substring(0, subString.length() -1);
			stringWidth = fm.stringWidth(subString);
		}
		return subString;
	}
	public int getxCenter(Graphics2D g2d, String text) {
		FontMetrics fm = g2d.getFontMetrics(); 
		int stringWidth = fm.stringWidth(text);
		int stringAscent = fm.getAscent();
		int xCoordinate = (getxAvaliWidth() / 2 - stringWidth / 2);
		return xCoordinate;
	}
	
	public int getxAvaliWidth() {
		return getWidth() - getxStart() * 2;
	}
	
	public int incyText() {
		yStart += yTextInc;
		return yStart;
	}
	
	public int incTitleText() {
		yStart += yTitleTextInc;
		return yStart;
	}
	
	/**
	 * geter,setter 方法区
	 */
	public int getHeight() {
		return height;
	}
	public int getyCount() {
		return yCount;
	}
	public void setyCount(int yCount) {
		this.yCount = yCount;
	}
	public void setHeight(int height) {
		this.height = height;
	}
	public int getWidth() {
		return width;
	}
	public void setWidth(int width) {
		this.width = width;
	}
	public int getxStart() {
		return xStart;
	}
	public void setxStart(int xStart) {
		this.xStart = xStart;
	}
	public int getyStart() {
		return yStart;
	}
	public void setyStart(int yStart) {
		this.yStart = yStart;
	}
	public int getyTextInc() {
		return yTextInc;
	}
	public void setyTextInc(int yTextInc) {
		this.yTextInc = yTextInc;
	}
	public int getyTitleTextInc() {
		return yTitleTextInc;
	}
	public void setyTitleTextInc(int yTitleTextInc) {
		this.yTitleTextInc = yTitleTextInc;
	}
	
	
}
